package com.example.demo.controller;

import com.example.demo.dao.ClassificationTableDao;
import com.example.demo.pojo.ClassificationTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class FeiLei {
 @Autowired
  private ClassificationTableDao classificationTableDao;
  @RequestMapping("/fenlei")
  public String fenlei(Model model){
     List<ClassificationTable> list=classificationTableDao.findClassficationtableByPid(0);
     model.addAttribute("yiji",list);
     return "fenlei";
  }
  //添加分类
    @RequestMapping("/insertClaa")
    public String insert(String name){
      ClassificationTable table=new ClassificationTable();
      table.setDescriptionofspecies(name);
      classificationTableDao.insertSelective(table);
      return "fenlei";
    }
    @RequestMapping("/selectClass")
  public String select(Model model){
      List<ClassificationTable> list=classificationTableDao.findClassficationtableByPid(0);
      List<ClassificationTable> list1=new ArrayList<>();
      for (int i = 0; i <list.size() ; i++) {
          ClassificationTable classificationTable=new ClassificationTable();
          classificationTable .setDescriptionofspecies(list.get(i).getDescriptionofspecies());
          List<ClassificationTable> list2=classificationTableDao.findClassficationtableByPid(list.get(i).getClassificationid());
          classificationTable.setList(list2);
          list1.add(classificationTable);
      }
      model.addAttribute("quqnbu",list1);
      return "fenlei";
  }

}
